﻿<?php   
       //include_once('init.php');

 
$data= selectmore('cate',1);

    // print_r($data);die;
        if(!empty($_POST)) { 
   
          if(!empty($_FILES['file']['name']['0'])){  //$_FILES['file']['name']值是非空的
            $filelist=array();//新建数组
            foreach ($_FILES['file']['name'] as $key => $v) {
              $filelist[$key]['name']=$v;
              $filelist[$key]['type']=$_FILES['file']['type'][$key];//则将$_FILES['file']['name']的下标存入对应的新数字里面
              $filelist[$key]['tmp_name']=$_FILES['file']['tmp_name'][$key];
              $filelist[$key]['error']=$_FILES['file']['error'][$key];
              $filelist[$key]['size']=$_FILES['file']['size'][$key];
              # code...
            }                     //重新排序

            foreach ($filelist as $value) {
              
            $savepath=update($value);

              # code...
            }
        }



    
     
       
      $_POST['send_user']=$_SESSION['admin']['username'];
      $_POST['url']= empty($savepath)?'':$savepath;


      $_rows=add($GLOBALS['c'],$_POST);
//编写插入数据的sql语句
$sql="SELECT news.* ,admin.username,cate.name FROM `news`,`cate`,`admin` WHERE news.cate_id=cate.id and news.send_user = admin.id";
$result=mysqli_query($GLOBALS['link'],$sql);
while ($arr=mysqli_fetch_assoc($result)) {
  $data[]=$arr;
  # code...
}

    //判断影响的行数是否大于0，大于表示添加成功则跳到新闻列表页面，小于则失败则返回原来的页面
    if ($_rows>0) {
      $id=mysqli_insert_id($link);
      $constr=file_get_contents("http://127.0.0.1/cms/index.php?c=news&a=new_info&id=$id");
      file_put_contents("./html/$id.html",$constr);


        echo '<script>alert("添加成功"); location.href="index.php?c=news&a=list&admin=1";</script>';die;
        # code...
    }else{
        echo'<script>alert("添加成功");history.go(-1);</script>';die;
    }

        }


  if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

    $_GET['cate_id'] = $_GET['type'];
     // print_r($_GET);die;
     $_GET['send_user'] = $_SESSION['admin']['id'];
     
  
    if($_GET['news_qu']>0){
      //移除指定数组中的下标 

    unset($_GET['c'],$_GET['a'],$_GET['news_qu'],$_GET['admin']);

      $_rows=add($GLOBALS['c'],$_GET);


      echo $_rows;die;

     
      //判断是否来自ajax的数据
  
} 
}


 include VIEW_PATH.$admin.'layout.html';

 //先做添加以作基础//